package com.tsing.bms.controller;

import com.tsing.bms.service.IDepotService;
import com.tsing.bms.vo.req.DepotAddReqVo;
import com.tsing.bms.vo.req.DepotUpdateReqVo;
import com.tsing.bms.vo.req.IdReqVo;
import com.tsing.bms.vo.req.IdsReqVo;
import com.tsing.bms.vo.resp.DepotRespVo;
import com.tsing.common.annotations.SystemLog;
import com.tsing.common.utils.ResultUtil;
import com.tsing.common.vo.ResultData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author TheTsing
 * @since 2021-03-29
 */
@Api(tags = "停车场管理")
@RestController
@RequestMapping("/depot")
public class DepotController {

    @Autowired
    private IDepotService depotService;

    @PostMapping("/addDepot")
    @ApiOperation(value = "新增停车场")
    @SystemLog(description = "新增停车场")
    public ResultData addDepot(@Validated @RequestBody DepotAddReqVo reqVo) {
        depotService.addDepot(reqVo);
        return ResultUtil.success();
    }

    @DeleteMapping("/deleteDepot")
    @ApiOperation(value = "删除停车场")
    @SystemLog(description = "删除停车场")
    public ResultData deleteDepot(@Validated @RequestBody IdsReqVo reqVo) {
        depotService.deleteDepot(reqVo);
        return ResultUtil.success();
    }

    @GetMapping("/getDepot")
    @ApiOperation(value = "获取单个停车场信息")
    @SystemLog(description = "获取单个停车场信息")
    public ResultData<DepotRespVo> getDepotById(@Validated IdReqVo reqVo) {
        return ResultUtil.success(depotService.getDepotById(reqVo));
    }

    @PutMapping("/updateDepot")
    @ApiOperation(value = "修改停车场信息")
    @SystemLog(description = "修改停车场信息")
    public ResultData updateDepot(@Validated @RequestBody DepotUpdateReqVo reqVo) {
        depotService.updateDepot(reqVo);
        return ResultUtil.success();
    }

    @GetMapping("/depotList")
    @ApiOperation(value = "停车场列表")
    @SystemLog(description = "停车场列表")
    public ResultData<List<DepotRespVo>> depotList() {
        return ResultUtil.success(depotService.depotList());
    }

}
